using Glue;
using Glue.Internals;
using GlueTests.Builders;
using Xunit;

namespace GlueTests.RelationContainerTests
{
    public class When_RelateTowardsLeft_is_called
    {
        public class GuiPerson { public int Id { get; set; } }
        public class DomainPerson { public int Id { get; set; } }

        private readonly Mapping<DomainPerson, GuiPerson> mapping;

        public When_RelateTowardsLeft_is_called()
        {
            mapping = new Mapping<DomainPerson, GuiPerson>();
            mapping.RelateTowardsLeft(master => master.Id, x => x.Id);
        }

        [Fact]
        public void Should_not_be_a_relation_towards_right()
        {
            var relationsToMaster = mapping.Relations.GetRelationsTowardsRight();
            Assert.Equal(0, relationsToMaster.Count);
        }

        [Fact]
        public void Should_be_a_relation_towards_left()
        {
            var relationsToMaster = mapping.Relations.GetRelationsTowardsLeft();
            Assert.Equal(1, relationsToMaster.Count);
        }

        [Fact]
        public void Should_be_a_relation_in_AllRelations()
        {
            Assert.Equal(1, mapping.Relations.Count);
        }

        [Fact]
        public void Should_contain_a_property_on_left_Side()
        {
            Assert.True(mapping.Relations.IsRelatedTowardsOnLeftSide(new PropertyBuilder(typeof(DomainPerson), "Id").Build()));
        }

        [Fact]
        public void Should_Not_contain_a_property_on_right_Side()
        {
            Assert.False(mapping.Relations.IsRelatedTowardsOnRightSide(new PropertyBuilder(typeof(DomainPerson), "Id").Build()));
        }
    }
}